const http = require('http')
const fs = require('fs')

const app = http.createServer((req, res) => {
  let pathname = req.url
  if (pathname === '/') {
    pathname = '/index.html'
  }

  if (pathname !== '/favicon.ico') {
    fs.readFile(`static${pathname}`, (err, data) => {
      if (err) {
        console.log(`404`)
      } else {
        res.writeHead(200, {'Content-Type': 'text/html;charset=utf-8'})
        res.write(data)
        res.end()
      }
    })
  }
})

app.listen(8081)